'use strict';

const BaseController = require('../core/base_controller');

class Controller extends BaseController {
    async uploadFile() {
        let {files, fields} = await this.uploadsFile('images');
        try {
            for (const key in files) {
                let file = files[key]
                let data = {
                    id: file.id,
                    file_name: file.name + file.extname,
                    file_path: file.relative_path,
                    original_name: file.originalFilename,
                    file_size: file.size,
                    file_suffix: file.extname,
                };
                await this.ctx.model.FileInfo.create(data)
            }
            this.success(files)
        } catch (e) {
            this.error(e)
            throw e
        }
    }

    async getId() {
        this.success(this.ctx.helper.getId())
    }

}

module.exports = Controller;
